#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int FindStart(vector<int>& nums, int target)
    {
        int left = 0, right = nums.size();
        while (left < right)
        {
            int mid = (right - left) / 2 + left;
            if (nums[mid] < target) left = mid + 1;
            else if (nums[mid] >= target) right = mid;
        }
        if (left < nums.size() && nums[left] == target) return left;
        else return -1;
    }
    int FindEnd(vector<int>& nums, int target)
    {
        int left = 0, right = nums.size() - 1;
        while (left <= right)
        {
            int mid = (right - left) / 2 + left;
            if (nums[mid] <= target) left = mid + 1;
            else if (nums[mid] > target) right = mid - 1;
        }
        if (right >= 0 && nums[right] == target) return right;
        else return -1;
    }
    vector<int> searchRange(vector<int>& nums, int target) {
        if (nums.size() == 0) return { -1, -1 };
        vector<int> res(2);
        res[0] = FindStart(nums, target);
        res[1] = FindEnd(nums, target);
        return res;
    }
};